﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using FileMonitor.Service.ProcessMonitor.Contract;
using FileMonitor.Service.ProcessMonitor.Model;


namespace FileMonitor.Service.ProcessMonitor.Service
{
    public class MonitorProcessService:IMonitorProcessService
    {
        public Dictionary<string, MonitorProcessInfo> GetAllProcessInfo()
        {
            return Manager.ProcessOperationManager.Current.GetMonitorProcessInfo();
        }
        public OperationResult ReStartProcess(string processName)
        {
            try
            {
                Manager.ProcessOperationManager.Current.StopProcess(processName);
                Manager.ProcessOperationManager.Current.StartProcess(processName);
                return new OperationResult() { Flag = 1 };
            }
            catch (Exception ex)
            {
                return new OperationResult() { Flag = 0, Message=ex.Message };
            }
        }
        public OperationResult StartProcess(string processName)
        {
             return   Manager.ProcessOperationManager.Current.StartProcess(processName);
        }
        public OperationResult StopProcess(string processName)
        {
            return Manager.ProcessOperationManager.Current.StopProcess(processName);
        }
        public OperationResult ReverseFile(FileInfo fi, string processName)
        {
            return Manager.ProcessOperationManager.Current.ReverseFile(fi, processName);
        }
        public List<FileInfo> GetFileInfo(FileState fileState, string processName)
        {
            try
            {
                return Manager.ProcessStateMonitorManager.Current.GetFileInfos(ProcessManager.Processes[processName], fileState);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public OperationResult RefreshProcesses()
        {
          return Manager.ProcessOperationManager.Current.RefreshProcesses();
        }
    }
}
